﻿@using SCMS.Resource
@model SCMS.UI.Models.TenderAnalysis

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div class="partialViewCard">
    <div class="partialViewCardHeader"><h3>@Resources.TenderAnalysis_String_TenderAnalysisEvaluation</h3></div>
    @if (Model.CanEdit)
    {
        <center>
            @Ajax.ActionLink(Resources.TenderAnalysis_ViewTenderDetails_EditTA, "Index", new { id = "EditTA" }, new AjaxOptions
       {
           UpdateTargetId = "tenderDiv",
           LoadingElementId = "loading",
           Url = Url.Action("EditTA/" + Model.EntityTenderAnalysis.Id),
           OnSuccess = "disableTAForm(1);initTAEdit();"
       }) | 
            @Ajax.ActionLink(Resources.TenderAnalysis_ViewTenderDetails_DeleteTA, "Index", new { id = "DeleteTA" }, new AjaxOptions
       {
           UpdateTargetId = "tenderDiv",
           LoadingElementId = "loading",
           Url = Url.Action("DeleteTA/" + Model.EntityTenderAnalysis.Id),
           Confirm = string.Format(Resources.Global_String_ConfirmDelete, Model.EntityTenderAnalysis.RefNumber),
           OnSuccess = "usermsg('" + Resources.TenderAnalysis_ViewTenderDetails_TADeleted + "');if (document.getElementById('table') != null) {initSorter();sorter.size(50);}"
       })
        </center>
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th align="center">
                @Resources.Global_String_Date
            </th>
            <th align="center">
                @Resources.Global_String_TenderAnalyaisNo
            </th>
            <th align="center">
                @Resources.Global_String_OrderRequestNo
            </th>
            <th align="center">
                @Resources.Global_String_ORCurrency
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntityTenderAnalysis.AnalysisDate.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.RefNumber
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.OrderRequest.RefNumber
            </td>
            <td align="center">
                @ViewBag.Currency
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left">
                @Resources.TenderAnalysis_String_TAIntroductionText
            </td>
        </tr>
    </table>
    @if (Model.HasSuppliers)
    {

        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <th align="center">
                    @Resources.Global_String_Description
                </th>
                @foreach (var item in Model.SupplierName)
                {
                    <th align="center">
                        @Html.DisplayFor(modelItem => item)
                    </th>
                }
            </tr>
            @{int x = 0; int cols = 1 + Model.SupplierName.Count; }
            @foreach (var item in Model.TBiderQuotes)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.ItemDescription)
                    </td>
                    @foreach (var subItem in item.UnitCost)
                    { 
                        <td align="right">
                            @subItem.ToString("#,##0.00")
                        </td>
                    }
                </tr>
            }
            @if (Model.TransportCost.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_TransportCost
                    </td>
                    @foreach (var item in Model.TransportCost)
                    {
                        <td align="right">
                            @item.ToString("#,##0.00")
                        </td>
                    }
                </tr>
            }
            <tr>
                <td>
                    <b>@Resources.Global_String_TotalCost</b>
                </td>
                @foreach (var item in Model.TotalCost)
                {
                    <td align="right">
                        <b>@item.ToString("#,##0.00")</b>
                    </td>
                }
            </tr>
            <tr class="gridheader">
                <td align="center" colspan="@cols">
                    @Resources.Global_String_TermsAndConditions
                </td>
            </tr>
            @if (Model.ShippingTerm.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_ShippingTerms
                    </td>
                    @foreach (var item in Model.ShippingTerm)
                    {
                        <td align="right">
                            @Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.DeliveryTime.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.GoodsReceivedNote_LoadGRNVerifyItems_DeliveryDate
                    </td>
                    @foreach (var item in Model.DeliveryTime)
                    {
                        <td align="right">
                            @item.ToString("dd/MM/yyyy")
                        </td>
                    }
                </tr>
            }
            @if (Model.Warrant.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.TenderAnalysis_String_Warranty
                    </td>
                    @foreach (var item in Model.Warrant)
                    {
                        <td align="right">
                            @Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.TermzOfPayment.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_PaymentTerms
                    </td>
                    @foreach (var item in Model.TermzOfPayment)
                    {
                        <td align="right">
                            @Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
            @if (Model.others.Count > 0)
            {
                <tr>
                    <td>
                        @Resources.Global_String_Other
                    </td>
                    @foreach (var item in Model.others)
                    {
                        <td align="right">
                            @Html.DisplayFor(modelItem => item)
                        </td>
                    }
                </tr>
            }
        </table>
    }
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <td valign="top" align="left">
                @Resources.Global_String_Recommendation:
            </td>
        </tr>
        <tr>
            <td>
                @Model.EntityTenderAnalysis.Recommendation
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th style="width: 30%;">
                @Resources.Global_String_PreparedBy
            </th>
            <th style="width: 30%;">
                @Resources.Global_String_Title
            </th>
            <th style="width: 20%;">
                @Resources.Global_String_Date
            </th>
            <th style="width: 20%;">
                @Resources.Global_String_Signature
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.EntityTenderAnalysis.Staff1.Person.FirstName &nbsp; @Model.EntityTenderAnalysis.Staff1.Person.OtherNames
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.Staff1.Designation.Name
            </td>
            <td align="center">
                @Model.EntityTenderAnalysis.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td align="center">
                @if (Model.EntityTenderAnalysis.Staff1.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntityTenderAnalysis.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th style="width: 19%;">
                @Resources.TenderAnalysis_ViewTenderDetails_Conclusion
            </th>
            <th style="width: 27%;">
                @Resources.Global_String_Recommendation
            </th>
            <th style="width: 27%;">
                @Resources.Global_String_Recommendation
            </th>
            <th style="width: 27%;">
                @Resources.Global_String_Recommendation
            </th>
        </tr>
        <tr>
            <td>
                @Resources.Dashboard_DocsDashboard_Approved / @Resources.Global_String_Rejected
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    if (Model.TenderEvaluators[0].HasApproved.Value)
                    { 
                        <font color="green"><b>@Resources.Dashboard_DocsDashboard_Approved</b></font>
                    }
                    else
                    { 
                        <font color="red"><b>@Resources.Global_String_Rejected</b></font>
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    if (Model.TenderEvaluators[1].HasApproved.Value)
                    { 
                        <font color="green"><b>@Resources.Dashboard_DocsDashboard_Approved</b></font>
                    }
                    else
                    { 
                        <font color="red"><b>@Resources.Global_String_Rejected</b></font>
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    if (Model.TenderEvaluators[2].HasApproved.Value)
                    { 
                        <font color="green"><b>@Resources.Global_String_Authorized</b></font>
                    }
                    else
                    { 
                        <font color="red"><b>@Resources.Global_String_Rejected</b></font>
                    }
                }
            </td>
        </tr>
        <tr>
            <td>
                @Resources.TenderAnalysis_String_SupplierChosen
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    if (Model.TenderEvaluators[0].RecommendedSupplierId != null)
                    { 
                        @Model.TenderEvaluators[0].Supplier.Name
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    if (Model.TenderEvaluators[1].RecommendedSupplierId != null)
                    { 
                        @Model.TenderEvaluators[1].Supplier.Name
                    }
                }
            </td>
            <td align="center">
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    if (Model.TenderEvaluators[2].RecommendedSupplierId != null)
                    { 
                        @Model.TenderEvaluators[2].Supplier.Name
                    }
                }
            </td>
        </tr>
        <tr>
            <td>
                @Resources.TenderAnalysis_ViewTenderDetails_AdditionalAction
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    @Model.TenderEvaluators[0].Remarks
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    @Model.TenderEvaluators[1].Remarks
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    @Model.TenderEvaluators[2].Remarks
                }
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left">
                @Resources.TenderAnalysis_ViewTenderDetails_ConclusionText
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
        border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr class="gridheader">
            <th style="width: 19%;" class="gridheader">
                @Resources.Approver_ApproverList_Authorization
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionApprovedBy
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionApprovedBy
            </th>
            <th style="width: 27%;">
                @Resources.TenderAnalysis_String_TenderConclusionAuthorizedBy
            </th>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3)
                { 
                    @Model.TenderEvaluators[0].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[0].Staff.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3)
                { 
                    @Model.TenderEvaluators[1].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[1].Staff.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3)
                { 
                    @Model.TenderEvaluators[2].Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.TenderEvaluators[2].Staff.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3)
                { 
                    @Model.TenderEvaluators[0].Staff.Designation.Name
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3)
                { 
                    @Model.TenderEvaluators[1].Staff.Designation.Name
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3)
                { 
                    @Model.TenderEvaluators[2].Staff.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                { 
                    @Model.TenderEvaluators[0].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                { 
                    @Model.TenderEvaluators[1].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                { 
                    @Model.TenderEvaluators[2].DateApproved.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 0 && Model.TenderEvaluators[0].Priority != 3 && Model.TenderEvaluators[0].HasApproved != null)
                {
                    if (Model.TenderEvaluators[0].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[0].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 1 && Model.TenderEvaluators[1].Priority != 3 && Model.TenderEvaluators[1].HasApproved != null)
                {
                    if (Model.TenderEvaluators[1].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[1].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
            <td>
                @if (Model.TenderEvaluators.Count > 2 && Model.TenderEvaluators[2].Priority == 3 && Model.TenderEvaluators[2].HasApproved != null)
                {
                    if (Model.TenderEvaluators[2].Staff.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.TenderEvaluators[2].Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                }
            </td>
        </tr>
    </table>
    <hr />
    @if (Model.EntityTenderAnalysis.IsAuthorized == true && UserContext.HasPermission(StandardPermissionProvider.TenderAnalysisPrint))
    {
        <a class="btn btn-primary"  href="@Url.Action("Index", "TA", new { area = "Reports", TAid = Model.TenderAnalysisId })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            @Resources.Budget_ViewBudget_DownloadPdf</a>
    }
    <br />
</div>
<br />
<p>
    @Ajax.ActionLink(Resources.Global_String_BackToList, "ViewTenders", new { id = "ViewTenders" }, new AjaxOptions
{
    UpdateTargetId = "tenderDiv",
    LoadingElementId = "loading",
    Url = Url.Action("ViewTenders"),
    OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(10);}"
})
</p>
